def barbie(q):
    w = True
    for o in range(2, int(q ** 0.5)+1):
        if q % o == 0:
            w = False
            break
    return w






e = int(input())
if e < 1000 or e > 9999:
    print(0)
else:
    kapibara = str(e)
    MAX = 0
    for i in range(len(kapibara)):
        for r in range(i+ 1, len(kapibara)+1):
            num = int(kapibara[i:r])
            if barbie(num):
                MAX = max(MAX, num)
print(MAX)